﻿using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.IdentityModel.Protocols.OpenIdConnect;
using Microsoft.IdentityModel.Tokens;
using System.Text;

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.
var secretKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes("UwItrlfVrqDr01QLpT8AGhF8N9PEJBjH"));
builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
    .AddJwtBearer(options =>
    {
        options.Configuration = new OpenIdConnectConfiguration();
        options.Authority = "http://localhost:5000/";
                    //options.Audience = "resource-server";
                    //options.IncludeErrorDetails = true;
                    options.RequireHttpsMetadata = false;
        options.TokenValidationParameters = new TokenValidationParameters
        {
            IssuerSigningKey = secretKey,
            ValidAudience = "Audience",
            ValidIssuer = "http://localhost:5000/",
            ValidateIssuerSigningKey = true,
            ValidateLifetime = true,
            ClockSkew = TimeSpan.Zero
        };
    });

builder.Services.AddControllers();

var app = builder.Build();

// app.UseHttpsRedirection();

app.UseAuthorization();

app.MapControllers();

app.Run();

